package com.ljc.study;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author clj
 * @date 2023/7/11
 * @desc
 */
public class RegTest {
    public static void main(String[] args) {

//        String videoLinkRaw = "0.07 wse:/ 吾行养车都行推出优惠福利，88元全车内外精洗护理 包含手工泡沫洗车、驾驶室内部吹灰吸尘、脚垫清洗、发动机舱吹尘清洁、车内雾化除菌# 汽车保养与维修 # 精洗养护 # 精致洗车护理 # 专业维修保养  https://v.douyin.com/iJekSg4x";
        String videoLinkRaw = "0.07 wse:/ 吾行养车都行推出优惠福利，88元全车内外精洗护理 包含手工泡沫洗车、驾驶室内部吹灰吸尘、脚垫清洗、发动机舱吹尘清洁、车内雾化除菌# 汽车保养与维修 # 精洗养护 # 精致洗车护理 # 专业维修保养  https://v.douyin.com/iJekSg4x/";
//        String videoLinkRaw = "1.53 UYz:/ # 暴雨倾盆而下 天漏了啊  https://v.douyin.com/iJecFD4e 复制此链接，打开Dou音搜索，直接观看视频！";
//        String videoLinkRaw = "1.53 UYz:/ # 暴雨倾盆而下 天漏了啊  https://v.douyin.com/iJecFD4e/ 复制此链接，打开Dou音搜索，直接观看视频！";

        String videoLink = getVideoLink(videoLinkRaw);

    }

    public static String getVideoLink(String videoLinkRaw) {
        String videoLink = videoLinkRaw.substring(videoLinkRaw.lastIndexOf("http"), videoLinkRaw.lastIndexOf("/") + 1);

        System.out.println("1 : " + videoLink);

        if ("https://v.douyin.com/".equals(videoLink)) {
            videoLink = videoLinkRaw.substring(videoLinkRaw.lastIndexOf("http"));

            System.out.println("2 : " + videoLink);

            if(videoLink.contains("复制此链接，打开Dou音搜索，直接观看视频！")) {
                videoLink = videoLink.replace("复制此链接，打开Dou音搜索，直接观看视频！", "");
                System.out.println("3 : " + videoLink);

            }

            videoLink = videoLink.trim();

            if (!"/".equals(videoLink.substring(videoLink.length() - 1))) {
                videoLink = videoLink + "/";
                System.out.println("4 : " + videoLink);
            }


        }
        return videoLink;
    }
}
